const jwt = require("jsonwebtoken");
const secretKey = "2308";  // 秘钥

function genToken(data, expiresIn = 30 * 60) {
    return jwt.sign(data, secretKey, { expiresIn: expiresIn });
}

function verifyToken(token) {
    try {
        var data = jwt.verify(token, secretKey);
        var { iat, exp, ...info } = data;
        return info;  // {}
    } catch (err) {
        return false;
    }
}

module.exports = {
    genToken,
    verifyToken,
}